<?php
namespace app\common\model;

use think\Model;
use think\Request;

class PositionContent extends Model
{
    public function insertData($data){
        return $this->saveAll([$data]);
    }

    public function selectData($data){
        if(isset($data['title']) && $data['title']) {
            $data['title'] = array('like', '%'.$data['title'].'%');
        }
        return $this->where($data)->order('listorder desc, id desc')->paginate(2, false, [
            'query' => Request::instance()->param()]);
    }
    public function findData($id){
        $data = $this->where('id', $id)->find();
        return $data;
    }

    public function updateById($id, $data){
        if(!$id || !is_numeric($id)) {
            throw_exceptions("ID不合法");
        }
        if(!$data || !is_array($data)) {
            throw_exceptions("更新的数据不合法");
        }
        return $this->save($data,['id' => $id]);
    }

    public function updateStatusById($id, $status){
        return $this->save(['status'=>$status],['id'=>$id]);
    }
   
    
}